package transformFactory;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.log4j.Logger;

public class TransformDate {

	private static final Logger logger = Logger.getLogger(TransformDate.class);

	public Date Str2Date(String str) throws ParseException {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date = sdf.parse(str);
		return date;
	}

	public String Date2Str(Date date) {
		logger.info("date");
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		String dateStr = sdf.format(date);
		return dateStr;
	}

	public boolean isSameDate(Date date1, Date date2) {
		String str1 = Date2Str(date1);
		String str2 = Date2Str(date2);
		if (date1 == null || date2 == null) {
			logger.info("输入日期为空！");
			return false;
		} else if (str1.equals(str2)) {
			return true;
		} else {
			return false;
		}
	}
}
